package org.jradweb.core.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.jradweb.core.controller.AbstractMultiActionController;
import org.jradweb.core.controller.JMultiActionController;
import org.springframework.web.servlet.handler.AbstractHandlerMapping;

/**
 * a substitute for spring SimpleUrlHandlerMapping .
 * use UrlMapResolver to map url to handler
 * 
 * Created On 2008-7-1
 * @see <code>org.jradweb.core.web.JUrlHandlerMapping</code>
 * @author <a href="mailto:wagzhi@gmail.com">Paul Wang</a>
 * @version $Id: JUrlHandlerMapping.java 149 2008-10-10 03:10:10Z wagzhi $
 */
public class JUrlHandlerMapping extends AbstractHandlerMapping {
	private UrlMapResolver urlMapResolver;

	public UrlMapResolver getUrlMapResolver() {
		return urlMapResolver;
	}

	public void setUrlMapResolver(UrlMapResolver urlMapResolver) {
		this.urlMapResolver = urlMapResolver;
	}

	@Override
	protected Object getHandlerInternal(HttpServletRequest request)
			throws Exception {
		Map<String, String> params = this.urlMapResolver.getParamters(request
				.getRequestURI());

		request.setAttribute(CommonAttributes.REQUEST_URL_PARAMETERS, params);
		
		String controllerName = params.get(CommonAttributes.CONTROLLER_NAME);
		if (controllerName == null) {
			return null;
		}
		
		Object controller=this.getApplicationContext().getBean(controllerName+"Controller");
		
		
		return controller;
	}

}
